<template>
    <div>
        <vue-office-docx :src="docxURL" style="height: 100vh;" v-if="docxURL" />
        <vue-office-excel :src="excelURL" style="height: 100vh;" v-else-if="excelURL" />
        <vue-office-pdf :src="pdfURL" v-else-if="pdfURL" />
    </div>
</template>

<script>
import VueOfficeDocx from '@vue-office/docx'
import VueOfficeExcel from '@vue-office/excel'
import '@vue-office/excel/lib/index.css'
import VueOfficePdf from '@vue-office/pdf'
import apiURL from '../../api/apiURL';

export default {
    components: {
        VueOfficeDocx,
        VueOfficeExcel,
        VueOfficePdf
    },
    data() {
        return {
            READ_FILE_URL: apiURL.READ_FILE_URL,
            docxURL: void 0,
            excelURL: void 0,
            pdfURL: void 0
        }
    },
    mounted() {
        window.sessionStorage.setItem('TOKEN_KEY', this.$route.query.id)
        switch (this.$route.query.fileUrl.match(/[^.]+$/)[0]) {
            case "doc":
            case "docx":
                this.docxURL = this.READ_FILE_URL + 'word/' + this.$route.query.fileUrl;
                break;
            case "xls":
            case "xlsx":
                this.excelURL = apiURL + 'excel/' + this.$route.query.fileUrl;
                break;
            // case "ppt":
            // case "pptx":
            //     filePath = this.$route.query.file;
            //     break;
            case "pdf":
                this.pdfURL = apiURL + 'pdf/' + this.$route.query.fileUrl;
                break;
            default:
                console.log('直接下载')
        }
    }
}
</script>

<style scoped></style>